package main

import (
	"fmt"
	"sync"
)

func main() {

	ch1 := make(chan struct{}, 1)
	ch2 := make(chan struct{})

	wg := sync.WaitGroup{}
	wg.Add(2)

	go func() {
		defer wg.Done()
		for i := 1; i < 5; i += 2 {
			<-ch1
			fmt.Println(i)
			ch2 <- struct{}{}
		}
	}()

	go func() {
		defer wg.Done()
		for i := 2; i < 6; i += 2 {
			<-ch2
			fmt.Println(i)
			ch1 <- struct{}{}
		}
	}()
	ch1 <- struct{}{}
	wg.Wait()
}
